import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout, QLabel
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap

class SaveFileDemo(QWidget):
    def __init__(self):
        super().__init__()
        self.init_ui()
        
    def init_ui(self):
        layout = QVBoxLayout()
        
        self.info_label = QLabel('保存路径将显示在这里')
        self.info_label.setAlignment(Qt.AlignCenter)
        
        save_btn = QPushButton('保存文件')
        save_btn.clicked.connect(self.save_file)
        
        layout.addWidget(self.info_label)
        layout.addWidget(save_btn)
        self.setLayout(layout)
        self.setWindowTitle('保存文件对话框演示')
        
    def save_file(self):
        from PyQt5.QtWidgets import QFileDialog
        
        file_name, selected_filter = QFileDialog.getSaveFileName(
            self,
            "保存文件",
            "untitled.txt",  # 默认文件名
            "文本文件 (*.txt);;CSV文件 (*.csv);;所有文件 (*)"
        )
        
        if file_name:
            self.info_label.setText(f"保存路径: {file_name}")
            # 在实际应用中，这里会执行文件保存操作
        else:
            self.info_label.setText("用户取消了保存")


            
if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = SaveFileDemo()
    window.show()
    sys.exit(app.exec_())